package com.app.micaihu.view.set;

import android.os.Build;
import android.os.Bundle;

import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

import com.alibaba.sdk.android.feedback.impl.FeedbackAPI;
import com.app.micaihu.R;
import com.app.micaihu.base.BaseOldActivity;
import com.app.micaihu.manager.UserInforManager;
import com.app.utils.ChannelUtil;
import com.app.utils.util.osutils.StatusBarUtils;

import org.json.JSONObject;

import java.util.concurrent.Callable;


/**
 * 阿里百川反馈
 * Created by Guo on 2016/11/28.
 *
 */
public class AliFeedBackActivity extends BaseOldActivity {


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        isInit = false;
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_alifeedback);

        StatusBarUtils.setupStatusBarView(this, R.color.common_bg_color_2,R.color.common_bg_color_10);
        StatusBarUtils.setStatusBarTextColor(this,true);

        FeedbackAPI.activity = this; // 设置activity

        final FragmentManager fm = getSupportFragmentManager();
        final FragmentTransaction transaction = fm.beginTransaction();
        final Fragment feedback = FeedbackAPI.getFeedbackFragment();
        // note: important
        FeedbackAPI.setFeedbackFragment(new Callable() {
            @Override
            public Object call() throws Exception {
                transaction.replace(R.id.content, feedback);
                transaction.commit();
                return null;
            }
        }, null);


        JSONObject jsonObject = new JSONObject();
        try {
            jsonObject.put("SDK", Build.VERSION.SDK_INT);// sdk版本
            jsonObject.put("channel", ChannelUtil.getChannel());//
            if(UserInforManager.getInstance().isLogin()){
                jsonObject.put("uid", UserInforManager.getInstance().getUserInfor().getUid());//用户id
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        FeedbackAPI.setAppExtInfo(jsonObject);

    }


    @Override
    protected void onDestroy() {
        super.onDestroy();
        FeedbackAPI.cleanFeedbackFragment();
        FeedbackAPI.cleanActivity();
    }
}
